package com.xjnt.tvos.tvlibs.jsbridge;

import com.xjnt.tvos.tvlibs.jsbridge.data.DataBuilder;
import com.xjnt.tvos.tvlibs.jsbridge.data.ParamConsts;

/**
 * JS 调用 Java 回调处理
 * Created by caoyong on 18-1-11.
 */

public class CallProcess {
    private BridgeManager bridgeManager;
    private DataBuilder request;

    CallProcess(BridgeManager bridgeManager, DataBuilder request) {
        this.bridgeManager = bridgeManager;
        this.request = request;
    }

    public void onCompleted(IClientCallback clientCallback) {
        DataBuilder response = clientCallback.setResponse();
        String callbackId = request.get(ParamConsts.KEY_CALLBACK_ID, String.class);
        response.put(ParamConsts.KEY_RESPONSE_ID, callbackId);
        this.bridgeManager.sendToClient(response.toDataString());
    }
}
